package com.bob.common.bean;

import cn.hutool.json.JSONObject;
import org.eclipse.jgit.diff.DiffEntry;
import org.eclipse.jgit.revwalk.RevCommit;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 提交信息
 */
public class CommitInfo {
    //  提交人 提交内容
    private String  commitPerson,message,commitid;
    // 提交时间
    private Date commitDate;
    // 差异文件信息
    private List<DiffEntry> diffEntries = new ArrayList<>();

    public CommitInfo(RevCommit commit) {
        this.commitDate = commit.getAuthorIdent().getWhen();//提交时间
        this.commitPerson = commit.getAuthorIdent().getName();//提交人
        this.message = commit.getFullMessage();//提交日志
        this.commitid = commit.getName();
    }

    public Date getCommitDate() {
        return commitDate;
    }


    public String getCommitPerson() {
        return commitPerson;
    }


    public String getMessage() {
        return message;
    }


    public List<DiffEntry> getDiffEntries() {
        return diffEntries;
    }

    public void setCommitPerson(String commitPerson) {
        this.commitPerson = commitPerson;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getCommitid() {
        return commitid;
    }

    public void setCommitid(String commitid) {
        this.commitid = commitid;
    }

    public void setCommitDate(Date commitDate) {
        this.commitDate = commitDate;
    }

    public void setDiffEntries(List<DiffEntry> diffEntries) {
        this.diffEntries = diffEntries;
    }

    @Override
    public int hashCode() {
        return this.commitid.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        CommitInfo obj1 = (CommitInfo) obj;
        return this.commitid.equals(obj1.getCommitid());
    }

    @Override
    public String toString() {
        return new JSONObject(this).toJSONString(4);
    }
}
